import Levenshtein



# 通用相似度匹配
def word_similarity(word, corpus):
    max = 0.0
    matched_item = ["", ""]
    for row in corpus:
        matching = Levenshtein.jaro_winkler(word.strip(), row[1].strip())
        if matching > max:
            max = matching
            matched_item = row

        if matching == 1.0:
            break

    return max, matched_item


# 反转后相似度匹配
def word_similarity_reverse(word, corpus):
    max = 0.0
    matched_item = ["", ""]
    for row in corpus:
        matching = Levenshtein.jaro_winkler(word.strip()[::-1], row[1].strip()[::-1])
        if matching > max:
            max = matching
            matched_item = row

        if matching == 1.0:
            break

    return max, matched_item


if __name__ == "__main__":
    # str1 = '洛阳白马'
    # str2 = '洛阳白马集团有限责任公司职工'
    # str2 = '洛阳平民'

    str1 = "苏州大学附属第二医院浒关院区"
    str2 = "兰州大学第二医院"
    res1 = Levenshtein.jaro_winkler(str1, str2)
    res2 = Levenshtein.jaro_winkler(str1[::-1], str2[::-1])
    print(res1)
    print(res2)
